<template>
  <div class="box">
    <!-- 表单 -->
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="上传图片" prop="region">
        <el-upload
          action="https://jsonplaceholder.typicode.com/posts/"
          list-type="picture-card"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove"
        >
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="" />
        </el-dialog>
      </el-form-item>
      <!-- 单选按钮 -->
      <el-form-item label="状态" prop="region">
        <div class="duanx">
          <el-radio v-model="radio" label="1">上架</el-radio>
          <el-radio v-model="radio" label="0">下架</el-radio>
        </div>
      </el-form-item>
      <!-- 产品分类 -->
      <el-form-item label="产品分类" prop="region">
        <div class="fenlei">
          <el-cascader
            :options="options"
            :props="{ checkStrictly: true }"
            clearable
          ></el-cascader>
        </div>
      </el-form-item>
      <el-form-item label="产品分组" prop="region">
        <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="产品名称" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="产品卖点" prop="desc">
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>
      <el-form-item label="活动性质" prop="type">
        <el-checkbox-group v-model="ruleForm.type">
          <el-checkbox label="商家配送" name="type"></el-checkbox>
          <el-checkbox label="用户自提" name="type"></el-checkbox>
        </el-checkbox-group>
      </el-form-item>
         <el-form-item label="运费设置" prop="desc">
        <el-select v-model="value" placeholder="请选择">
    <el-option
      v-for="item in optionsy"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即创建</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 上传图片
      dialogImageUrl: "",
      dialogVisible: false,
      // 单选按钮
      radio: "1",
      // 运费设置
       optionsy: [{
          value: '1',
          label: '1'
        }, {
          value: '2',
          label: '2'
        }, {
          value: '3',
          label: '奥特曼'
        }, {
          value: '4',
          label: '678uih'
        }],
        value: '',
      // 选择器
      options: [
        {
          value: "yundong",
          label: "运动服饰",
        },
        {
          value: "meiwei",
          label: "美味零食",
        },
        {
          value: "shoji",
          label: "手机数码",
          children: [
            {
              value: "axure",
              label: "手机通讯",
            },
            {
              value: "sketch",
              label: "智能设备",
            },
            {
              value: "jiaohu",
              label: "珠宝钟表",
            },
          ],
        },
        {
          value: "meizhuang",
          label: "美妆护肤",
        },
      ],
      // 表单
      ruleForm: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change",
          },
        ],
        type: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个活动性质",
            trigger: "change",
          },
        ],
        resource: [
          { required: true, message: "请选择活动资源", trigger: "change" },
        ],
        desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }],
      },
    };
  },
  methods: {
    // 上传图片
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    // 表单
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.clearfix:after {
  content: "";
  clear: both;
  display: block;
}

/* 输入框 */
.el-input {
  width: 30%;
}
>>> .el-textarea__inner {
  width: 30%;
}
</style>